package com.ruoyi.warehousemanager.controller;

import java.nio.file.WatchService;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.warehousemanager.domain.Item;
import com.ruoyi.warehousemanager.domain.Warehouse;
import com.ruoyi.warehousemanager.pojo.WarehouseVO;
import com.ruoyi.warehousemanager.service.IWarehouseService;
import com.ruoyi.warehousemanager.service.ItemService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.warehousemanager.domain.OutWarehouse;
import com.ruoyi.warehousemanager.service.IOutWarehouseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 出库管理Controller
 *
 * @author h
 * @date 2023-06-15
 */
@RestController
@RequestMapping("/warehousemanager/outwarehouse")
public class OutWarehouseController extends BaseController
{
    @Autowired
    private IOutWarehouseService outWarehouseService;
    @Autowired
    private ItemService itemaService;

    @Autowired
    private IWarehouseService warehouseaService;
    /**
     * 查询出库管理列表
     */
    @PreAuthorize("@ss.hasPermi('warehousemanager:outwarehouse:list')")
    @GetMapping("/list")
    public TableDataInfo list(OutWarehouse outWarehouse)
    {
        startPage();
        List<OutWarehouse> list = outWarehouseService.selectOutWarehouseList(outWarehouse);
        return getDataTable(list);
    }

    /**
     * 导出出库管理列表
     */
    @PreAuthorize("@ss.hasPermi('warehousemanager:outwarehouse:export')")
    @Log(title = "出库管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OutWarehouse outWarehouse)
    {
        List<OutWarehouse> list = outWarehouseService.selectOutWarehouseList(outWarehouse);
        ExcelUtil<OutWarehouse> util = new ExcelUtil<OutWarehouse>(OutWarehouse.class);
        util.exportExcel(response, list, "出库管理数据");
    }

    /**
     * 获取出库管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehousemanager:outwarehouse:query')")
    @GetMapping(value = "/{outId}")
    public AjaxResult getInfo(@PathVariable("outId") Long outId)
    {
        return success(outWarehouseService.selectOutWarehouseByOutId(outId));
    }



    /**
     * 新增出库管理
     */
    @PreAuthorize("@ss.hasPermi('warehousemanager:outwarehouse:add')")
    @Log(title = "出库管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OutWarehouse outWarehouse)
    {
        return toAjax(outWarehouseService.insertOutWarehouse(outWarehouse));
    }

    /**
     * 修改出库管理
     */
    @PreAuthorize("@ss.hasPermi('warehousemanager:outwarehouse:edit')")
    @Log(title = "出库管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OutWarehouse outWarehouse)
    {
        return toAjax(outWarehouseService.updateOutWarehouse(outWarehouse));
    }

    /**
     * 删除出库管理
     */
    @PreAuthorize("@ss.hasPermi('warehousemanager:outwarehouse:remove')")
    @Log(title = "出库管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{outIds}")
    public AjaxResult remove(@PathVariable Long[] outIds)
    {
        return toAjax(outWarehouseService.deleteOutWarehouseByOutIds(outIds));
    }
}
